<%--
  Created by IntelliJ IDEA.
  User: Fmc
  Date: 2022/6/6
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>登录</title>
        <link rel="stylesheet" href="static/layui-main/dist/css/layui.css">
        <script src="static/layui-main/src/layui.js"></script>
    </head>
    <body>
        <form class="layui-form" action="" id="loginForm" >
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="text" name="password" required lay-verify="required" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="loginBtn">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </body>
    <script>
        layui.use(['form','jquery'],function (){
            var form = layui.form;
            var $ = layui.jquery;

            form.on('submit(loginBtn)',function (data){
                $.ajax({
                    url: "${pageContext.request.contextPath}/login?method=login"
                    ,data: data.field
                    ,dataType: "json"
                    ,type: "post"
                    ,success: function (redata) {
                        if (redata.code == 0){
                            window.location.href = "${pageContext.request.contextPath}/showUser.jsp";
                        } else {
                            layer.msg(redata.msg);
                        }
                    }
                });
                return false;
            });
        })
    </script>
</html>
